Should not have to specify crates-io registry URL to replace-with
authorCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Tue, 13 Sep 2016 02:26:16 +0000 (22:26 -0400)
committerCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Mon, 26 Sep 2016 14:56:19 +0000 (10:56 -0400)
Since cargo knows crates-io's registry URL and, anyway, you're trying to
say that you don't want to use crates-io.

src/cargo/sources/config.rs
tests/local-registry.rs

index e40b6a7d546c3688ce64160325b3fe53ac60ccd3..01205ff51b7e22b88c1bcb5406698a7225e305a6 100644 (file)
@@ -146,6 +146,9 @@ a lock file compatible with `{orig}` cannot be generated in this situation
             path.push(s);
             srcs.push(try!(SourceId::for_directory(&path)));
         }
+        if name == "crates-io" && srcs.is_empty() {
+            srcs.push(try!(SourceId::crates_io(self.config)));
+        }
 
         let mut srcs = srcs.into_iter();
         let src = try!(srcs.next().chain_error(|| {
index b974f01c4c8037f7db73206b2185dbc0d52583ce..7643a92aa572604f1e44b41d9d13b54a88d14830 100644 (file)
@@ -348,3 +348,51 @@ unable to verify that `foo v0.0.1` is the same as when the lockfile was generate
 
 "));
 }
+
+#[test]
+fn crates_io_registry_url_is_optional() {
+    let root = paths::root();
+    t!(fs::create_dir(&root.join(".cargo")));
+    t!(t!(File::create(root.join(".cargo/config"))).write_all(br#"
+        [source.crates-io]
+        replace-with = 'my-awesome-local-registry'
+
+        [source.my-awesome-local-registry]
+        local-registry = 'registry'
+    "#));
+
+    Package::new("foo", "0.0.1")
+            .local(true)
+            .file("src/lib.rs", "pub fn foo() {}")
+            .publish();
+
+    let p = project("bar")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "bar"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            foo = "0.0.1"
+        "#)
+        .file("src/lib.rs", r#"
+            extern crate foo;
+            pub fn bar() {
+                foo::foo();
+            }
+        "#);
+
+    assert_that(p.cargo_process("build"),
+                execs().with_status(0).with_stderr(&format!("\
+[UNPACKING] foo v0.0.1 ([..])
+[COMPILING] foo v0.0.1
+[COMPILING] bar v0.0.1 ({dir})
+[FINISHED] [..]
+",
+        dir = p.url())));
+    assert_that(p.cargo("build"), execs().with_status(0).with_stderr("\
+[FINISHED] [..]
+"));
+    assert_that(p.cargo("test"), execs().with_status(0));
+}